package com.greenold.residing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.greenold.approvalRecord.domain.ApprovalRecord;
import com.greenold.residing.domain.ApprovalRecordDTO;
import com.greenold.residing.domain.LeaveRequestDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.greenold.common.annotation.Log;
import com.greenold.common.core.controller.BaseController;
import com.greenold.common.core.domain.AjaxResult;
import com.greenold.common.enums.BusinessType;
import com.greenold.residing.domain.LeaveRequest;
import com.greenold.residing.service.ILeaveRequestService;
import com.greenold.common.utils.poi.ExcelUtil;
import com.greenold.common.core.page.TableDataInfo;

/**
 * 请假管理Controller
 * 
 * @author ruoyi
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/residing/leaveRequest")
public class LeaveRequestController extends BaseController
{
    @Autowired
    private ILeaveRequestService leaveRequestService;

    /**
     * 查询请假管理列表
     */
    @PreAuthorize("@ss.hasPermi('residing:leaveRequest:list')")
    @GetMapping("/list")
    public TableDataInfo list(LeaveRequest leaveRequest)
    {
        startPage();
        List<LeaveRequestDTO> list = leaveRequestService.selectLeaveRequestList(leaveRequest);
        return getDataTable(list);
    }



    /**
     * 获取请假管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('residing:leaveRequest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(leaveRequestService.selectLeaveRequestById(id));
    }

    /**
     * 新增请假管理
     */
    @PreAuthorize("@ss.hasPermi('residing:leaveRequest:add')")
    @Log(title = "请假管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LeaveRequest leaveRequest)
    {
        return toAjax(leaveRequestService.insertLeaveRequest(leaveRequest));
    }

    /**
     * 修改请假管理
     */
    @PreAuthorize("@ss.hasPermi('residing:leaveRequest:edit')")
    @Log(title = "请假管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LeaveRequest leaveRequest)
    {
        return toAjax(leaveRequestService.updateLeaveRequest(leaveRequest));
    }

    /**
     * 删除请假管理
     */
    @PreAuthorize("@ss.hasPermi('residing:leaveRequest:remove')")
    @Log(title = "请假管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(leaveRequestService.deleteLeaveRequestByIds(ids));
    }

    /**
     * 请假审批 Approval
     */
    @PostMapping("/approval")
    public AjaxResult approval(@RequestBody ApprovalRecordDTO approvalRecordDTO)
    {
        return toAjax(leaveRequestService.approval(approvalRecordDTO));
    }

    /*
     * 根据老人id查看老人基本信息
     * @param id 老人id
     * @return 老人基本信息
     * */
    @GetMapping(value = "/elder/{id}")
    public AjaxResult getElderInfo(@PathVariable("id") Integer id)
    {
        return success(leaveRequestService.selectElderInfoById(id));
    }

    /*
     * 查询所有老人基本信息
     * @return 所有老人基本信息
     * */
    @GetMapping(value = "/elder/list")
    public AjaxResult getElderList()
    {
        return success(leaveRequestService.getElderList());
    }

}
